﻿IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'proc_cm_SaveQuickAnnouncement')
BEGIN
    PRINT 'Dropping Procedure proc_cm_SaveQuickAnnouncement'
    DROP  Procedure  proc_cm_SaveQuickAnnouncement
END
GO

PRINT 'Creating Procedure proc_cm_SaveQuickAnnouncement'
GO

CREATE PROCEDURE [dbo].[proc_cm_SaveQuickAnnouncement]
	@pQuickAnnouncementTxt nvarchar(1024)
	, @pEffectiveDateFrom datetime = null
	, @pEffectiveDateTo datetime = null
	, @pEnabledInd bit = 0
AS
BEGIN
	SET NOCOUNT ON

	IF EXISTS (select top 1 null from [dbo].[tbl_quick_announcement])
	BEGIN
		UPDATE [dbo].[tbl_quick_announcement]
		SET 
			[quick_announcement_txt] = @pQuickAnnouncementTxt
			,[effective_date_from] = @pEffectiveDateFrom
			,[effective_date_to] = @pEffectiveDateTo
			,[enabled_ind] = @pEnabledInd
	END
	ELSE
	BEGIN
		INSERT INTO [dbo].[tbl_quick_announcement]
		(
			[quick_announcement_txt]
			,[effective_date_from]
			,[effective_date_to]
			,[enabled_ind]
		)
		VALUES
		(
			@pQuickAnnouncementTxt
			,@pEffectiveDateFrom
			,@pEffectiveDateTo
			,@pEnabledInd
		)
	END
END
GO

GRANT EXEC ON dbo.proc_cm_SaveQuickAnnouncement TO PUBLIC
GO


